<?php

/**
 * Departement filter form base class.
 *
 * @package    SdCommerce
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseDepartementFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'date'             => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'libelle'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'is_cloture'       => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'type'             => new sfWidgetFormFilterInput(),
      'telephone1'       => new sfWidgetFormFilterInput(),
      'telephone2'       => new sfWidgetFormFilterInput(),
      'fax'              => new sfWidgetFormFilterInput(),
      'email'            => new sfWidgetFormFilterInput(),
      'ville_id'         => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Ville'), 'add_empty' => true)),
      'initiale'         => new sfWidgetFormFilterInput(),
      'stock'            => new sfWidgetFormChoice(array('choices' => array('' => 'yes or no', 1 => 'yes', 0 => 'no'))),
      'id_vehicule'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Vehicule'), 'add_empty' => true)),
      'type_departement' => new sfWidgetFormChoice(array('choices' => array('' => '', 'point de vente' => 'point de vente', 'Depot' => 'Depot'))),
      'created_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'       => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'm_article_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Article')),
    ));

    $this->setValidators(array(
      'date'             => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDate(array('required' => false)), 'to_date' => new sfValidatorDateTime(array('required' => false)))),
      'libelle'          => new sfValidatorPass(array('required' => false)),
      'is_cloture'       => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'type'             => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'telephone1'       => new sfValidatorPass(array('required' => false)),
      'telephone2'       => new sfValidatorPass(array('required' => false)),
      'fax'              => new sfValidatorPass(array('required' => false)),
      'email'            => new sfValidatorPass(array('required' => false)),
      'ville_id'         => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Ville'), 'column' => 'id')),
      'initiale'         => new sfValidatorPass(array('required' => false)),
      'stock'            => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'id_vehicule'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Vehicule'), 'column' => 'id')),
      'type_departement' => new sfValidatorChoice(array('required' => false, 'choices' => array('point de vente' => 'point de vente', 'Depot' => 'Depot'))),
      'created_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'       => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'm_article_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Article', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('departement_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addMArticleListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.StockArticle StockArticle')
      ->andWhereIn('StockArticle.article_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Departement';
  }

  public function getFields()
  {
    return array(
      'id'               => 'Number',
      'date'             => 'Date',
      'libelle'          => 'Text',
      'is_cloture'       => 'Boolean',
      'type'             => 'Number',
      'telephone1'       => 'Text',
      'telephone2'       => 'Text',
      'fax'              => 'Text',
      'email'            => 'Text',
      'ville_id'         => 'ForeignKey',
      'initiale'         => 'Text',
      'stock'            => 'Boolean',
      'id_vehicule'      => 'ForeignKey',
      'type_departement' => 'Enum',
      'created_at'       => 'Date',
      'updated_at'       => 'Date',
      'm_article_list'   => 'ManyKey',
    );
  }
}
